package com.et.protocol.core;

import androidx.annotation.Keep;

import com.et.protocol.ano.GuideCode;

import java.io.IOException;


@Keep
public final class ETInlets implements IGuide {

    @Keep
    public static class Builder {
        private IObserver observer;
        private String portName = "/dev/ttymxc1";
        private int baud = 19200;

        public Builder() {
        }

        public Builder configPortName(String portName) {
            this.portName = portName;
            return this;
        }

        public Builder configBaud(int baud) {
            this.baud = baud;
            return this;
        }

        public Builder configObserver(IObserver observer) {
            this.observer = observer;
            return this;
        }

        public ETInlets build() throws IOException {
            return new ETInlets(this);
        }
    }

    private final Swift swift;

    private ETInlets(Builder b) throws IOException {
        swift = Swift.newInstance(b.portName, b.baud, b.observer);
    }

    @Override
    public boolean guide(int code) {
        if (code == GuideCode.GUI_88) {
           // TODO clear logcat
        }
        if (swift == null) return false;
        return swift.guide(code);
    }

    @Override
    public boolean guide2(int code, byte[] data) {
        if (swift == null) return false;
        return swift.guide2(code, data);
    }

    @Override
    public int query(int code) {
        if (swift == null) return -1;
        return swift.query(code);
    }

    @Override
    public byte[] query2(int code) {
        if (swift == null) return null;
        return swift.query2(code);
    }

    @Override
    public byte[] query3(int code, int box) {
        if (swift == null) return null;
        return swift.query3(code, box);
    }
}
